/*
 * public class ShowBillboardBean
 * author: adam barney
 * backing bean that holds an uneditable copy of a billboard object.
 * useful for displaying a billboard.
 */

/*
 * This file is part of WhatItDo.
 *
 * WhatItDo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WhatItDo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WhatItDo.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.sourceforge.whatitdo.billboardWeb;

import java.util.ArrayList;
import net.sourceforge.whatitdo.billboard.model.Billboard;
import net.sourceforge.whatitdo.billboard.model.DataHelper;

public class ShowBillboardBean {
    Billboard billboard = new Billboard();
    
    String slideshowTextAsString = new String();
    String tickerText = new String();
    
    public String getSlideshowTextAsString() {
	getBillboard();
	slideshowTextAsString = ArrayListToString(billboard.getSlideshowText());
	System.out.println("showing slides: " + slideshowTextAsString);
        return slideshowTextAsString;
    }
    public void setSlideshowTextAsString(String slideshowTextAsString) {
        this.slideshowTextAsString = slideshowTextAsString;
    }
    public String getTickerText() {
	getBillboard();
	tickerText = billboard.getTickerText();
	System.out.println("showing tickertext: " + tickerText);
        return tickerText;
    }
    public void setTickerText(String tickerText) {
        this.tickerText = tickerText;
    }
    
    private String ArrayListToString(ArrayList<String> aList) {

	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < aList.size(); i++) {
	    if (i == (aList.size() - 1)) {
		sb.append("\"");
		sb.append(aList.get(i).toString());
		sb.append("\"");
	    } else {
		sb.append("\"");
		sb.append(aList.get(i).toString());
		sb.append("\", ");
	    }

	}
	String rtrn = sb.toString();
	return rtrn;

	
    }
    public Billboard getBillboard() {
	String id = DataHelper.getPublishedBillboardId();
	System.out.println("showing billboard id: " + id);
	this.billboard.loadBillboard(id);
	System.out.println("showing billboard name: " + billboard.getName());
	System.out.println("with ticker text = " + billboard.getTickerText());
	setBillboard(billboard);
        return billboard;
    }
    public void setBillboard(Billboard billboard) {
        this.billboard = billboard;
    }
    

}
